﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Microsoft.WPF.Samples
{
    public static class ListFiles
    {
        /// <summary>
        /// Creates a list which contains all filenames in a specific folder
        /// </summary>
        /// <param name="Root">Folder which contains files to be listed</param>
        /// <param name="SubFolders">True for scanning subfolders</param>
        /// <returns></returns>
        public static List<string> GetFileList(string Root, bool SubFolders)
        {
            List<string> FileArray = new List<string>();
            try
            {
                string[] Files = System.IO.Directory.GetFiles(Root);
                string[] Folders = System.IO.Directory.GetDirectories(Root);

                for (int i = 0; i < Files.Length; i++)
                {
                    FileArray.Add(Files[i].ToString());
                }

                if (SubFolders == true)
                {
                    for (int i = 0; i < Folders.Length; i++)
                    {
                        FileArray.AddRange(GetFileList(Folders[i], SubFolders));
                    }
                }
            }
            catch (Exception Ex)
            {
                throw (Ex);
            }
            return FileArray;
        }


        public static List<string> GetJPGList(string Root, bool SubFolders)
        {
            List<string> FileArray = new List<string>();
            try
            {
                string[] Files = System.IO.Directory.GetFiles(Root);
                string[] Folders = System.IO.Directory.GetDirectories(Root);

                for (int i = 0; i < Files.Length; i++)
                {
                    if (Files[i].ToString().Contains(".jpg") || Files[i].ToString().Contains(".png"))
                    {
                        FileArray.Add(Files[i].ToString());
                    }
                }

                if (SubFolders == true)
                {
                    for (int i = 0; i < Folders.Length; i++)
                    {
                        if (Files[i].ToString().Contains(".jpg") || Files[i].ToString().Contains(".png") )
                        {
                            FileArray.AddRange(GetFileList(Folders[i], SubFolders));
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Es konnten keine Bilder der Slightshow geladen werden");
            }
            return FileArray;
        }
    }
}
